package com.ziyia.fragmentbestpractice;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

public class NewsContentActivity extends AppCompatActivity {

//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_news_content);
//        String title = getIntent().getStringExtra("news_title");
//        String content = getIntent().getStringExtra("news_content");
//
//        if (title != null && content != null) {
//
//            NewsContentFragment newsContentFragment = new NewsContentFragment();
//            newsContentFragment.refresh(title, content);
//
//        }
//    }
//
//    public void actionStart(Context context, String title, String content) {
//        Intent intent = new Intent(context, NewsContentActivity.class);
//        intent.putExtra("news_title", title);
//        intent.putExtra("news_content", content);
//        context.startActivity(intent);
//    }

    public static void actionStart(Context context, String newsTitle,
                                   String newsContent) {
        Intent intent = new Intent(context, NewsContentActivity.class);
        intent.putExtra("news_title", newsTitle);
        intent.putExtra("news_content", newsContent);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_news_content);
        String newsTitle = getIntent().getStringExtra("news_title");
// 获取传入的新闻标题
        String newsContent = getIntent().getStringExtra("news_content");
// 获取传入的新闻内容
        NewsContentFragment newsContentFragment = (NewsContentFragment) this.getSupportFragmentManager().findFragmentById(R.id.news_content_fragment);
        newsContentFragment.refresh(newsTitle, newsContent);
// 刷新NewsContentFragment界面
    }
}